//品牌管理
$(function(){
	$('#equipmentList').getList({
		"initData":{
			"num":1,
			"size":10,
			"qurtyType":"2"
		},
		"url":site.apiUrl+"/moble/userBriefing/selectMyUserBriefingList",// 数据请求url
		"type":"post",
		"ajaxform":true,
		"checkname":"datachk", //选择器名称，为空不显示选择器
		"col":[  //数据列
			{"field":"userNikeName","display":"姓名","width":"3"},
			{"field":"briefingName","display":"简报名称","width":"3"},
			{"field":"briefingContext","display":"简报内容","width":"3"},
			// {"field":"lat","display":"经度","width":"1.5"},
			// {"field":"log","display":"纬度","width":"1.5"},
			// {"field":"isUsingDisplay","display":"是否启用","width":"2"},
			{"field":"creatTime","display":"发布时间"}
		],
		"option":[ //操作按钮配置
			/*{"icon":"view","tip":"查看","fun":"brandView('{{id}}')"},  //icon: view,edit,add,del*/
			{"icon":"view","tip":"查看","fun":"brandEdit('{{id}}')"},  // 花括号内可以对应相关字段
			{"icon":"del","tip":"删除","fun":"deleteBrand('{{id}}')"}
		]
	});
	
	$("#isUsing").getSelect({
		type:"screen",
		label:"是否启用：",
		asName:"isUsing",
		code:"isUsing"
	});
	$("#equipmentType").getSelect({
		type:"screen",
		label:"设备类型：",
		asName:"equipmentType",
		code:"equipmentType"
	});
	
	//批量删除
	$("#batchDelBtn").click(function(){
		var c = "";
		$("input[name=datachk]:checked").each(function(){
			c += $(this).val()+',';
		});
		if(c!= null && c!=''){
			deleteBrand(c);
		}else{
			ly.toast("请选择删除项");
		}
		
	});

	//查询用户
	userList();
});

/**
 * 查询用户
 */
function userList(){
	var urls= site.gateUrl+'/sUsers/selectUsersList'
	request({
		url:urls,
		data:{
			"num":1,
			"size":30,
		},
		type:"get",
		'ajaxform':true,
		callback:function(f) {
			var htmls = '';
			var datas= f.result.list;
			if(f.code=="rest.success"){
				for (let i = 0; i < datas.length; i++) {
					htmls+="<option value='"+datas[i].id+"'>"+datas[i].nickName+"</option>"
				}
				$("#userList").append(htmls)
			}else{
				ly.toast(f.desc);
			}
		}
	});
}

//编辑
function brandEdit(id){
	ly.goto("Briefing-set.html?id="+id+"")
}

//删除
function deleteBrand(id){
	var url = site.apiUrl+"/moble/userBriefing/deleteUserBriefingByIds";
	ly.confirm("你确认删除吗？",function(){
		request({
			url:url,
			data:{"ids":id},
            type:"get",
            ajaxform:true,
			callback:function(f) {
				console.log(f);
				if(f.code=="rest.success"){
					ly.toast("删除成功");
					$("#equipmentList").getList.refresh();//刷新当前分页
				}
			}
		});	
	});
}
//查看
function commodityView(id){
	
	
}

function changePic(v, o, d) {
	if(d.picDisplay!=null && d.picDisplay!= ''){
		$(o).html("<img src="+d.picDisplay+" width='30' height='30'>");
	}else{
		$(o).html("<img src='"+site.interUrl+"images/default_head.jpg' width='30' height='30'>");
	}
    
}